import 'package:flutter/material.dart';
import 'package:test_flutter/helloWord/Home_page.dart';
import 'package:test_flutter/helloWord/category_page.dart';
import 'package:test_flutter/helloWord/left_drawer.dart';
import 'package:test_flutter/helloWord/message_page.dart';
import 'package:test_flutter/helloWord/right_drawer.dart';
import 'package:test_flutter/helloWord/setting_page.dart';
import 'package:test_flutter/helloWord/user_page.dart';

void main() {
  runApp(const MaterialApp(
    home: LayoutPage(),
  ));
}

class LayoutPage extends StatefulWidget {
  const LayoutPage({super.key});

  @override
  State<LayoutPage> createState() => _LayoutPageState();
}

class _LayoutPageState extends State<LayoutPage> {
  late int _currentIndex = 0;
  final List<Widget> _pages = const [
    HomePage(),
    CategoryPage(),
    MessagePage(),
    SettingPage(),
    UserPage()
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("hello flutter"),
          backgroundColor: Colors.blue,
        ),
        body: _pages[_currentIndex],
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: (value) {
            setState(() {
              _currentIndex = value;
            });
          },
          fixedColor: Colors.blue,
          iconSize: 24,
          type: BottomNavigationBarType.fixed,
          items: const [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
            BottomNavigationBarItem(icon: Icon(Icons.category), label: '分类'),
            BottomNavigationBarItem(icon: Icon(Icons.message), label: '消息'),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
            BottomNavigationBarItem(icon: Icon(Icons.people), label: '用户'),
          ],
        ),
        floatingActionButton: Container(
          height: 60,
          width: 60,
          padding: const EdgeInsets.all(4),
          margin: const EdgeInsets.only(top: 4),
          decoration: BoxDecoration(
              color: Colors.white, borderRadius: BorderRadius.circular(30)),
          child: FloatingActionButton(
            backgroundColor: _currentIndex == 2 ? Colors.red : Colors.blue,
            onPressed: () {
              setState(() {
                _currentIndex = 2;
              });
            },
            child: const Icon(Icons.add),
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        drawer: const LeftDrawer(),
        endDrawer: const RightDrawer(),
      ),
    );
  }
}
